/**
 * 作者：陈文斌 on 2019/1/27.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';

class ExpansionTileDialog extends Dialog {
  final List<Widget> tiles;

  ExpansionTileDialog({
    Key key,
    @required this.tiles,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        Navigator.pop(context);
      },
      child: Material(
        type: MaterialType.transparency,
        child: Stack(
          children: <Widget>[
            Positioned(
              right: 30,
              top: kToolbarHeight + 5,
              child: Container(
                height: 21,
                width: 21,
                color: Colors.white,
              ),
            ),
            Positioned(
              right: 15,
              top: kToolbarHeight + 5 + 7,
              child: ExpansionSection(
                tiles: tiles,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class ExpansionSection extends StatelessWidget {
  final List<Widget> tiles;

  ExpansionSection({
    Key key,
    @required this.tiles,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Offstage(
      offstage: tiles.length == 0,
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(2),
        ),
        child: ClipRRect(
          borderRadius: BorderRadius.circular(2),
          child: Column(
            children: tiles,
          ),
        ),
      ),
    );
  }
}

class ExpansionDialogTile extends StatelessWidget {
  final String title;
  final double height;
  final VoidCallback onTap;
  final Icon icon;
  final Image image;

  ExpansionDialogTile({
    Key key,
    @required this.title,
    this.onTap,
    this.icon,
    this.image,
    this.height = 40,
  }) : super(key: key);

  ExpansionDialogTile.icon({
    Key key,
    @required this.icon,
    @required this.title,
    this.onTap,
    this.image,
    this.height = 40,
  }) : super(key: key);

  ExpansionDialogTile.image({
    Key key,
    @required this.image,
    @required this.title,
    this.onTap,
    this.icon,
    this.height = 40,
  }) : super(key: key);

  TextStyle _titleTextStyle = TextStyle(
    color: AppColors.TextColor,
    fontSize: AppFontSizes.Font15,
    fontFamily: AppFontFamilies.PingFangSC,
    fontWeight: FontWeight.w500,
  );

  @override
  Widget build(BuildContext context) {
    return Container(
      height: height,
      child: Material(
        child: InkWell(
          onTap: onTap,
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 10),
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 10),
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    width: 1,
                    color: AppColors.LineColor,
                  ),
                ),
              ),
              child: Row(
                children: <Widget>[
                  icon != null ? icon : Container(),
                  image != null ? image : Container(),
                  PaddingSet.PaddingLeft(15),
                  Text(
                    title,
                    style: _titleTextStyle,
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
